package cn.hrlly.tao2shou.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.domain.Order;
import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.presenter.OrderDetailsPresenter;
import cn.hrlly.tao2shou.presenter.OrderDetailsPresenterImpl;
import cn.hrlly.tao2shou.utils.ImageUtil;
import cn.hrlly.tao2shou.view.base.BaseActivity;
import cn.hrlly.tao2shou.view.view_interface.OrderDetailsView;

public class OrderDetailsActivity extends BaseActivity implements OrderDetailsView {

    @Bind(R.id.ivCommodityPhoto)
    ImageView ivCommodityPhoto;
    @Bind(R.id.tvCommodityName)
    TextView tvCommodityName;
    @Bind(R.id.layoutCommodity)
    LinearLayout layoutCommodity;
    @Bind(R.id.tvSellerNickname)
    TextView tvSellerNickname;
    @Bind(R.id.tvSellerPhoneNumber)
    TextView tvSellerPhoneNumber;
    @Bind(R.id.tvBuyerNickname)
    TextView tvBuyerNickname;
    @Bind(R.id.tvBuyerPhoneNumber)
    TextView tvBuyerPhoneNumber;
    @Bind(R.id.tvTime)
    TextView tvTime;
    @Bind(R.id.tvLocation)
    TextView tvLocation;
    @Bind(R.id.tvPrice)
    TextView tvPrice;
    @Bind(R.id.tvOrderTime)
    TextView tvOrderTime;
    @Bind(R.id.tvBarterName)
    TextView tvBarterName;
    @Bind(R.id.tvBarterDescription)
    TextView tvBarterDescription;
    @Bind(R.id.layoutBarter)
    LinearLayout layoutBarter;
    private OrderDetailsPresenter orderDetailsPresenter;
    private Intent intent;
    private ImageLoader imageLoader;
    private String releaseId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_details);
        ButterKnife.bind(this);
        intent=getIntent();
        imageLoader=ImageLoader.getInstance();
        releaseId=null;
        orderDetailsPresenter=new OrderDetailsPresenterImpl(this);
        orderDetailsPresenter.showOrderDetails();
    }

    //layoutCommodity点击事件
    @OnClick(R.id.layoutCommodity)
    public void commodity(){
        Intent intent=new Intent(OrderDetailsActivity.this,CommodityDetailsActivity.class);
        intent.putExtra(Config.key_release_id,releaseId);
        startActivity(intent);
    }

    //对activity的操作
    @Override
    public String getOrderId() {
        return intent.getStringExtra(Config.key_order_id);
    }

    @Override
    public void showOrderDetails(Order order) {
        releaseId=order.getReleaseId();
        if(order.getTradeMethod()==0){
            layoutBarter.setVisibility(View.VISIBLE);
            tvBarterName.setText(order.getBarterName());
            tvBarterDescription.setText(order.getBarterDescription());
            //这里要有viewpager的操作
        }
        tvOrderTime.setText(order.getOrderTime());
        tvPrice.setText(order.getTradePrice());
        tvTime.setText(order.getTradeTime());
        tvLocation.setText(order.getTradeLocation());
        tvSellerNickname.setText(order.getSellerNickname());
        tvSellerPhoneNumber.setText(order.getSellerPhoneNumber());
        tvBuyerNickname.setText(order.getBuyerNickname());
        tvBuyerPhoneNumber.setText(order.getBuyerPhoneNumber());
        tvCommodityName.setText(order.getCommodityName());
        imageLoader.displayImage(order.getCommodityPhoto(),ivCommodityPhoto, ImageUtil.getOptions());
    }

    @Override
    public void showMessage(String errorMessage) {
        Toast.makeText(this,errorMessage,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showMessage(int errorMessage) {
        Toast.makeText(this,errorMessage,Toast.LENGTH_SHORT).show();
    }

}
